package com.cskaoyan._11block._03ex;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/6 17:30
 **/
/*
创建一个类Student，类中有多个构造器，请写代码统计外部创建Student对象的次数。
 */
public class Demo2 {
    public static void main(String[] args) {
        Student2 s1 = new Student2("zs");

        Student2 s2 = new Student2();

        System.out.println("一共创建了" + Student2.count + "个学生对象");

    }
}

class Student2{
    String name;
    static int count = 0;
    {
        // 使用构造代码块进行优化
        Student2.count++;
    }

    public Student2(String name) {

        this.name = name;
        //count++;
    }

    public Student2() {

        //count++;
    }
}
